package stattracker;

import java.util.ArrayList;
import java.util.Collection;
import java.util.TreeMap;

public class Halo3TeamMember implements java.io.Serializable 
{
	private static final long serialVersionUID = 1L;
	private String name;
	private TreeMap<Long, Halo3GameData> gamesPlayed;
	private ArrayList<Halo3GameData> allGames, teamGames;
	private int totalKills, totalDeaths, totalAssists;
	private int teamKills, teamDeaths, teamAssists;
	private int teamWins;
	
	public Halo3TeamMember(String gamertag)
	{
		name = gamertag;
		gamesPlayed = new TreeMap<Long, Halo3GameData>();
		allGames = new ArrayList<Halo3GameData>();
		teamGames = new ArrayList<Halo3GameData>();
		zeroStats();
	}
	
	public ArrayList<Halo3GameData> getAllGames()
	{
		return allGames;
	}
	
	public int getTeamWins()
	{
		return teamWins;
	}
	
	public int getTeamKills()
	{
		return teamKills;
	}
	
	public int getTeamDeaths()
	{
		return teamDeaths;
	}
	
	public int getTeamAssists()
	{
		return teamAssists;
	}
	
	public int getTotalKills()
	{
		return totalKills;
	}
	
	public int getTotalDeaths()
	{
		return totalDeaths;
	}
	
	public int getTotalAssists()
	{
		return totalAssists;
	}
	
	public String getName()
	{
		return name;
	}
	
	public TreeMap<Long, Halo3GameData> getGamesPlayed()
	{
		return gamesPlayed;
	}
	
	public ArrayList<Halo3GameData> getTeamGames()
	{
		return teamGames;
	}
	
	public void addGame(Halo3GameData g, boolean isTeamGame)
	{
		gamesPlayed.put(g.getID(), g);
		allGames.add(g);
		if(isTeamGame)
			teamGames.add(g);
	}
	
	public void compileStats()
	{
		zeroStats();
		Collection<Halo3GameData> c = gamesPlayed.values();
		ArrayList<Halo3GameData> games = new ArrayList<Halo3GameData>(c);
		
		for(Halo3GameData g : games)
		{
			totalKills += g.getDetail().getKills();
			totalDeaths += g.getDetail().getDeaths();
			totalAssists += g.getDetail().getAssists();
		}
		
		for(Halo3GameData g : teamGames)
		{
			teamKills += g.getDetail().getKills();
			teamDeaths += g.getDetail().getDeaths();
			teamAssists += g.getDetail().getAssists();
			
			if(g.getInfo().getPlacement().equals("1st"))
				teamWins++;
		}
	}
	
	private void zeroStats()
	{
		totalKills = 0; totalDeaths = 0; totalAssists = 0;
		teamKills = 0; teamDeaths = 0; teamAssists = 0;
		teamWins = 0;
	}

}
